<?php

declare(strict_types=1);

namespace app\seller\model;

use app\shop\model\Category as shopCategoryModel;
use app\shop\model\Shop;

class Brand extends Shop
{

    protected $name = 'shop_brand';

    protected $type = [
    ];

    // 追加属性
    protected $append = [
        'audit_status_text',
        'auth_type_text',
    ];


    public function auditStatusList()
    {
        return [
            '0' => '审核中',
            '1' => '审核通过',
            '2' => '审核驳回'
        ];
    }

    public function authTypeList()
    {
        return [
            'permanent' => '长期有效',
            'fixed' => '授权期限',
        ];
    }



    /**
     * 通用类型获取器
     *
     * @param string $value
     * @param array $data
     * @return string
     */
    public function getAuditStatusTextAttr($value, $data)
    {
        $value = $value ?: ($data['audit_status'] ?? null);

        $list = $this->auditStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    /**
     * 通用类型获取器
     *
     * @param string $value
     * @param array $data
     * @return string
     */
    public function getAuthTypeTextAttr($value, $data)
    {
        $value = $value ?: ($data['auth_type'] ?? null);

        $list = $this->authTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    // 定义获取分类名称的方法
    public function getCategoryNamesAttr($value, $data)
    {
        $categoryIds = explode(',', $data['category_ids']);
        $categories = shopCategoryModel::with('parent')->whereIn('id', $categoryIds)->select()->toArray();

        $category_text = [];
        if(!empty($categories)){
            foreach($categories as $key=>$val){
                if($val['parent']!=null){
                    $category_text[] = $val['name'].'>'.$val['parent']['name'];
                }else{
                    $category_text[] = $val['name'];
                }
            }
        }

        return implode(', ', $category_text);
    }


}
